import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';
import { viteMockServe } from 'vite-plugin-mock'

//按需引入
// import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default ({ command }) => {
  return defineConfig({
    // base: './',//根据打包生成地址，默认为'/'，可修改
    plugins: [
      vue(),
      viteMockServe({
        supportTs: false,
        logger: false,
        mockPath: "./mock"
      })
      //element按需导入
      // AutoImport({
      //   //element
      //   resolvers: [ElementPlusResolver()],
      // }),
      // Components({
      //   //element
      //   resolvers: [ElementPlusResolver()],
      // }),
    ],
    server: {
      open: true,
      host: 'localhost',
      port: 3000,
      https: false, // 是否开启 https
      // proxy: {
      //   '/api': {
      //     target: 'http://localhost:3001/',	//实际请求地址
      //     changeOrigin: true,
      //     pathRewrite: { '^api': '' }
      //   },
      // },
      cors: true,
    },
    build: {
      outDir: 'dist',
      assetsDir: 'assets',
      sourcemap: false,
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
    },
    define: { 'process.env': {} },
    resolve: {
      //使用@路径
      alias: {
        "@": path.resolve("./src"),
        "Components": path.resolve("./src/components"),
        "Utils": path.resolve("./src/util"),
        "Api": path.resolve("./src/services/api"),
        "Store": path.resolve("./src/store/modules"),
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          math: "always", // 括号内才使用数学计算
          globalVars: {
            // 全局变量
            mainColor: "red",
          },
        },
      },
    },
  })
}
